//
//  LCWebServicesManager.m
//  JKBiblicalReading
//
//  Created by admin on 2018/8/16.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LCWebServicesManager.h"

//#define NetworkToolGET [[NetworkTool sharedInstance] POSTFuYinWithUrlString:urlString input:parameters success:^(NSDictionary *dict) {\
//if (successBlock) {\
//successBlock(dict);\
//}\
//} failure:^(NSError *error) {\
//if (failureBlock) {\
//failureBlock(error);\
//}\
//}];

#define NetworkToolPOST [[NetworkTool sharedInstance] POSTFuYinWithUrlString:urlString input:parameters success:^(NSDictionary *dict) {\
if (successBlock) {\
successBlock(dict);\
}\
} failure:^(NSError *error) {\
if (failureBlock) {\
failureBlock(error);\
}\
}];

@implementation LCWebServicesManager

IMPLEMENTATION_SINGLETON(LCWebServicesManager)

- (void)getTagNumWithShengJingTitle:(NSString *)shengJingTitle success:(void (^)(NSDictionary *))successBlock failure:(void (^)(NSError *))failureBlock {
    NSString *chapter = [shengJingTitle substringWithinBoundsLeft:@"第" right:@"章"];
    NSString *book = [shengJingTitle substringWithinBoundsLeft:@"约" right:@"("];
    NSLog(@"book = %@", book);
    NSString *urlString = [NSString stringWithFormat:@"%@%@"
                           ,http_zongSJUrl,@"/bible/get_tag_num"
                           ];
    if (1) {
        NSLog(@"urlString = %@", urlString);
    }
    //   可选参数    @"fuid": [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"],
    
    NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                  book, @"book",
                                  chapter, @"chapter",
                                  nil];
    
    NSMutableDictionary *parameters
    = [NSMutableDictionary dictionaryWithDictionary:myDictionary];
    
    NetworkToolPOST
}

- (void)getDonateWithArray:(NSArray *)array page:(NSInteger)page type:(NSInteger)type success:(void (^)(NSDictionary *))successBlock failure:(void (^)(NSError *))failureBlock end:(void (^)(void))endBlock{
    
    NSString *urlString = [NSString stringWithFormat:@"%@%@"
                           ,http_zongSJUrl,@"/dynamic/get_donate"
                           ];
    if (1) {
        NSLog(@"urlString = %@", urlString);
    }
    if (array.count != 2) {
        NSLog(@"参数错误!");
        return;
    }
    NSMutableDictionary *parameters;
    if (type == 2) {
        //获取指定用户被打赏记录
        NSDictionary *myDictionary01;
        myDictionary01 = [NSDictionary dictionaryWithObjectsAndKeys:
                          array[0], @"tuid",//用户tuid
                          array[1], @"tid",//动态tid
                          @(page),@"page",
                          @"30",@"size",
                          nil];
        parameters = [NSMutableDictionary dictionaryWithDictionary:myDictionary01];
    }
    
    NetworkToolPOST
}
- (void)addDonateWithArray:(NSArray *)array type:(NSInteger)type success:(void (^)(NSDictionary *))successBlock failure:(void (^)(NSError *))failureBlock{
    
    NSString *urlString = [NSString stringWithFormat:@"%@%@"
                           ,http_toutiao,@"/user/donate"
                           ];
    if (1) {
        NSLog(@"urlString = %@", urlString);
    }
    NSMutableDictionary *parameters;
    
    if (type == 1) {
        //获取指定用户被打赏记录
        NSDictionary *myDictionary01;
        myDictionary01 = [NSDictionary dictionaryWithObjectsAndKeys:
                          array[0], @"credit",//福音值
                          array[1], @"note",//留言
                          //                          array[2], @"trade_no",//订单号
                          @"3", @"kind",//3 赠送动态id
                          array[2], @"resource_id",//
                          nil];
        
        parameters = [NSMutableDictionary dictionaryWithDictionary:myDictionary01];
    }
    
    NetworkToolPOST
}

@end
